<template>
  <div>
   <!-- 搜索栏 -->
   <el-form :inline="true" :model="search" class="demo-form-inline">
      <el-form-item label="关键字">
        <el-input v-model="search.keyWords" placeholder="关键字"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="fetchGoods" >查询</el-button>
      </el-form-item>
    </el-form>
   <!-- /搜索栏 -->
   <!-- 商品 -->
   <el-table
        :data="cates"
        height="400"
        border
        style="width: 100%">
        <el-table-column
          prop="goodsNum"
          label="订单号"
          >
        </el-table-column>
        <el-table-column
          prop="goodsType"
          label="订单类型">
        </el-table-column>
         <el-table-column
          prop="name"
          label="收件人"
          >
        </el-table-column>
         <el-table-column
          prop="goodsdesc"
          label="商品信息"
          >
          <template slot-scope="scope">
             <el-tooltip class="item" effect="light"  placement="bottom-end">
              <div style="width:400px" slot="content" >
                {{scope.row.goodsdesc}}
              </div>
              <span>
                  {{scope.row.goodsdesc
                ?(scope.row.goodsdesc.length>10 ?scope.row.goodsdesc.substr(0,12)+'...':scope.row.goodsdesc)
                :'暂无描述'}}
                </span>
              </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          prop="goodsimg"
          label="商品图片"
          >
            <template slot-scope="scope">
                <el-image
                    style="width: 50px; height: 50px"
                    :src="scope.row.goodsimg"
                    :preview-src-list="[scope.row.goodsimg]">
              </el-image>
          </template>
        </el-table-column>
         <el-table-column
          prop="pay"
          label="支付金额"
          >
        </el-table-column>
        <el-table-column
          prop="createAt"
          label="下单时间">
          <template slot-scope="scope">
                {{dayjs(scope.row.createAt).format('YYYY-MM-DD')}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="showDetails(scope.row.id)">详情</el-button>
            <el-button
            size="mini"
            type="danger"
            @click="DeleteCates(scope.row.id)">删除</el-button>
        </template>
        </el-table-column>
      </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total">
    </el-pagination>
  <!-- 弹窗 -->
  <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%">
      <person-msg :catess="detailes"/>
    </el-dialog>
  </div>
</template>

<script>
import PersonMsg from './Components/PersonMsg'
import * as dayjs from 'dayjs'
import { GoodsMsg, detailsGoods, deleteItem } from '_api'
export default {
  components: {
    PersonMsg
  },
  name: 'WebSetting',
  data () {
    return {
      search: {
        keyWords: ''
      },
      cates: [],
      page: 1,
      pageSize: 10,
      total: 0,
      dialogVisible: false,
      detailes: {}
    }
  },
  methods: {
    // 删除 点击id订单
    DeleteCates (id) {
      this.$confirm('此操作会删除此商品分类，是否继续？', '删除').then(() => {
        deleteItem(id).then((res) => {
          if (res.data.code === 200) {
            this.$message({
              message: '删除成功',
              type: 'success',
              duration: 1000,
              onClose: () => {
                this.$router.go(0)
              }
            })
          }
        })
      })
    },
    //  弹窗和传id 到达详情
    showDetails (id) {
      this.dialogVisible = true
      detailsGoods(id).then((res) => {
        if (res.data.code === 200) {
          this.detailes = {
            ...res.data.data
          }
        }
      })
    },
    //  分页跳转
    handleSizeChange (page) {
      this.page = page
      this.fetchGoods()
    },
    handleCurrentChange (pageSize) {
      this.pageSize = pageSize
      this.fetchGoods()
    },
    dayjs,
    // 获取订单数据
    fetchGoods () {
      GoodsMsg({
        ...this.search,
        page: this.page,
        pageSize: this.pageSize
      }).then((res) => {
        // console.log(res)
        if (res.data.code === 200) {
          this.cates = res.data.data.list
          this.total = res.data.data.total
        }
      })
    }
  },
  created () {
    this.fetchGoods()
  }
}
</script>

<style lang="scss" scoped>
.el-btn{
  margin-bottom: 10px;
}
.min-add{
    min-width: 800px !important;
}
</style>
